package com.community.process._1010.event.push;

import com.community.process._1010.common.api.CommonResult;
import com.community.process._1010.common.utils.ExternalApiUtils;
import com.community.process._1010.event.OvertimeOrderEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@RequiredArgsConstructor
@Slf4j
public class OvertimeOrderPush {


    @Async
    @EventListener(classes = OvertimeOrderEvent.class)
    public void cancelOrderEvent(OvertimeOrderEvent event) {
        if (StringUtils.hasLength(event.getOutTradeNo())) {
            // 超时订单更新入口
            CommonResult<String> result = ExternalApiUtils.overtimeOrder(event.getOutTradeNo());
            if (result.getData() == null) {
                log.info("超时订单更新入口：{}，{}",event.getOutTradeNo(),result.getMsg());
            }
        }
    }
}
